package main

import "fmt"

func getSubString(str string) string {
	var subString string
	var tempSubString string
	startIndex := -1
	m1 := make(map[rune]int)
	for endIndex := 0; endIndex < len([]rune(str)); endIndex++ {
		if tempIndex, ok := m1[[]rune(str)[endIndex]]; ok {
			if endIndex-tempIndex > len([]rune(tempSubString)) {
				subString = string([]rune(str)[tempIndex:endIndex])
			}
			for k := range m1 {
				delete(m1, k)
			}
			startIndex = tempIndex
			endIndex = tempIndex
		} else {
			tempSubString = string([]rune(str)[startIndex+1 : endIndex+1])
			m1[[]rune(str)[endIndex]] = endIndex
		}
		if len([]rune(tempSubString)) > len([]rune(subString)) {
			subString = tempSubString
		}
	}
	return subString
}

func main() {
	str := "abcabcbbfaeretwt"
	substring := getSubString(str)
	fmt.Printf("最长不含有重复字符的子串：%s", substring)
	fmt.Println()
	strzh := "yes我爱你中国！我爱你"
	fmt.Printf("最长不含有重复字符的子串：%s", getSubString(strzh))
}
